package Game;
import java.io.Serializable;

/**
 * Vehicle.java
 * 
 * This interface lists the necessary methods that a vehicle must implement to fit in with the game
 * 
 * @author Ray DeCuir
 * @version 1.2
 */
public abstract class Vehicle implements Serializable
{
	// the amount of weight that this vehicle can carry
	protected int weightCapacity;
	
	// the parts that compose this type of vehicle
	protected VehicleNode[] parts;

	
	/**
	 * isFunctional
	 * 
	 * This method returns a boolean denoting if a vehicle is functional to travel or not
	 * 
	 * @return A boolean denoting if a vehicle can travel or not
	 */
	
	public boolean isFunctional() {
		return findBrokenPart() == -1;
	}

	/**
	 * getWeightCapacity
	 * 
	 * This method returns an integer giving the maximum weight capacity for a particular vehicle
	 * 
	 * @return An integer giving the weight capacity of a particular vehicle
	 */
	public int getWeightCapacity() {
		return weightCapacity;
	}

	
	
	/**
	 * findBrokenPart()
	 * 
	 * This method traverses all of the parts of the Cart and checks to make sure that all of them are functional, 
	 * if one is found to be broken, that part is returned. Otherwise the method returns null
	 * 
	 * @return The id of the broken part, or -1 if no parts are broken 
	 */
	public int findBrokenPart()
	{
		for ( VehicleNode part : parts)
		{
			if ( !part.functional )
			{
				return part.id;
			}
		}
			return -1;
	}
	
	
	/**
	 * breakRandomVehiclePart
	 * 
	 * This method randomly breaks a part belonging to that vehicle
	 */
	public void breakRandomVehiclePart()
	{
		parts[(int)Math.random() * parts.length ].functional = false;
	}
	

	/**
	 * repair
	 * 
	 * Sets all parts of a vehicle to functional again so that it may move
	 * 
	 */

	public void repair() 
	{
		for ( VehicleNode part : parts)
		{
			part.functional = true;
		}
	}
	
	/**
	 * Gets the donkey that belongs to the vehicle, if there is one, null otherwise
	 * 
	 * @return The donkey
	 */
	public Donkey getDonkey()
	{
		return null;
	}
	
	/**
	 * Private class that manages the functional status and ItemList id of the parts that make up the vehicle
	 * 
	 * @author Ray
	 *
	 */
	public class VehicleNode implements Serializable
	{
		boolean functional;
		int id;
		
		public VehicleNode(int id)
		{
			functional = true;
			this.id = id;
		}
	}
}
